<style>
	.tableoos thead th{line-height:32px;border:1px solid #EDEDED; font-weight:bolder;}
	.tableoos tbody td{border:1px solid #EDEDED; line-height:24px;}
</style>
<script>
function lev(t,s) {
	var t = t;
	if ( s==1 )t.value = t.value.replace(/\D/g, ''); 
	if ( s==2 ) { t.value = t.value.replace(/[^0-9.]/g, ''); }
	if (t.value.length < 1 || t.value < 1) { t.value = 1 } else if (t.value > 9999) { t.value = parseInt(t.value.substring(0, 4)) };
} 

</script>
<h2 class="contentTitle">查看订单商品缺货</h2>
<div class="pageContent">
    <div class="pageFormContent" layouth="56" style="height: 290px; overflow: auto;">
        <fieldset>
            <fieldset>
                <legend>订单商品信息</legend>
                <div>
                    <table class="tableoos" width="100%" align="center">
                        <thead>
                        <tr align="center">
                            <th width="15%">订单编号</th>
                            <th>商品名称</th>
                            <th width="24%">有效数量</th>
                            <th width="24%">操作</th>
                        </tr>
                        </thead>
                        <tbody>
<if condition="empty($goods)">
                        <tr align="center">
                            <td colspan="4" style="padding:10px;border:0;color:#FB0000;" align="center">订单内没有商品!</td>
                        </tr>
	<else/>
	<volist name="goods" id="vo">
	<php>
		$oosnum=$vo['number'];
		if($goods_finance[$vo['product_id']]){
			foreach($goods_finance[$vo['product_id']] as $o){
				if($o['action']=='OOS' && $o['platform']=='SMW01'){
					$oosnum-=$o['number'];
				}
			}
		}
	</php>
                        <tr align="center">
                            <td rowspan="2" height="60" style="border-left:none;"><a href="#" target="_blank">{$vo['product_psn']}</a></td>
                            <td rowspan="2">{$vo['product_name']}<br>
								{$vo['price']/100|number_format=###,2} x {$vo['number']}
							</td>
							<td rowspan="2" id="oosnumnow_{$vo['id']}">
								{$oosnum}
							</td>
							<td>
{if $oosnum<1}
--
{else}
								<table width="100%">
								<tr>
								<td>缺货数量：</td>
								<td><input type="text" rel="{$vo['id']}" class="digits ossnum" style="width:30px;" name="ossnum" MaxLength="4" id="ossnum_{$vo['id']}" MaxLength="10" min="1" onkeyup="lev(this,1);"></td>
								<td><input rel="{$vo['id']}" type="button" value="缺货" class="oosbnt">
								<input type="hidden" id="refporid_{$vo['id']}" value="{$vo['product_id']}"></td></tr>
								</table>
								
{/if}
							</td>
                        </tr>
						<tr>
							<td>
{if $oosnum<1}
--
{else}
								<table width="100%">
								<tr><td>退款数量：</td><td><input style="width:30px;" class="digits" type="text" name="refundnum" id="refundnum_{$vo['id']}" MaxLength="4" onkeyup="lev(this,1);"></td>
								<td rowspan="2"><input rel="{$vo['id']}" type="button" value="退款" class="refundbnt"></td></tr>
								<tr><td>退款金额：</td><td><input style="width:30px;" type="text" name="refundmoney" id="refundmoney_{$vo['id']}" MaxLength="8" onkeyup="lev(this,2);"></td></tr>
								</table>
								
								
								
								
{/if}
							</td>
						</tr>
	</volist>
</if>
                        <tbody>
                        </table>
                    </div>
                    </fieldset>
{if $finance}
                    <fieldset>
                        <legend>订单缺货登记</legend>
<volist name="finance" id="f">
                        <dl class="nowrap">
                            <dt>{if $f['action']=='OOS'}缺货{else}退款{/if}</dt>
                            <dd>{$f['remark']}    {$f['value']/100|number_format=###,2} {$f['subject']}  x {$f['number']}         【{if $f['status']==1}已操作退款{else}未操作退款{/if}】</dd>
                        </dl>
</volist>
                    </fieldset>
{/if}
                </div>
            </div>
<script>
$(function(){
	$(".ossnum").change(function(){
		$this=$(this);
		$rel=$this.attr('rel');
		$ossnum=parseInt($($this).val());
		$ossnumnow=parseInt($("#oosnumnow_"+$rel).text());
		if($ossnum>$ossnumnow){
			$($this).val($ossnumnow);
		}
	});
	
	$(".oosbnt").click(function(){
		$this=$(this);
		$this.attr('disabled','true');
		$rel=$this.attr('rel');
		$ossnum=parseInt($("#ossnum_"+$rel).val());
		if($ossnum > 0){
			
			$ossnumnow=parseInt($("#oosnumnow_"+$rel).text());
			$refporid=parseInt($("#refporid_"+$rel).val());
			if($ossnum>=$ossnumnow){
				$ossnum=$ossnumnow;
				
			}
			var param={id:$rel,number:$ossnumnow,tonumber:$ossnum,porid:$refporid};
			var url="{:U('Order/do_oos')}";
			$.ajax({
				type:'POST',
				url:url,
				data:param,
				dataType:"json",
				cache: false,
				success:function(json){
					if(json.statusCode==200){
						$ossnumnow-=parseInt($ossnum);
						$("#oosnumnow_"+$rel).text($ossnumnow);
						if($ossnumnow>0){
							$this.removeAttr('disabled');
						}
						alert(json.message);
					}else{
						$this.removeAttr('disabled');
						alert(json.message);
					}
				},
			});//ajax
		}else{
			$this.removeAttr('disabled');
			alert("缺货数量必须大于0！");
			
		}
	});//click
	
	$(".refundbnt").click(function(){
		$this=$(this);
		$this.attr('disabled','true');
		$rel=$this.attr('rel');
		$ossnum=parseInt($("#refundnum_"+$rel).val());
		$money=parseInt($("#refundmoney_"+$rel).val());
		$ossnumnow=parseInt($("#oosnumnow_"+$rel).text());
		$refporid=parseInt($("#refporid_"+$rel).val());
		if($ossnum>$ossnumnow){
			alert("退款数量不能超过商品有效数量");
			return;
		}
		if($ossnum >0 && $money > 0){
			
			var param={id:$rel,number:$ossnum,money:$money,porid:$refporid};
			var url="{:U('Order/do_refund')}";
			$.ajax({
				type:'POST',
				url:url,
				data:param,
				dataType:"json",
				cache: false,
				success:function(json){
					if(json.statusCode==200){
						$ossnumnow-=parseInt($ossnum);
						$("#oosnumnow_"+$rel).text($ossnumnow);
						if($ossnumnow>0){
							$this.removeAttr('disabled');
						}
						alert(json.message);
					}else{
						$this.removeAttr('disabled');
						alert(json.message);
					}
				},
			});//ajax
		}else{
			$this.removeAttr('disabled');
			alert("退款数量和金额必须大于0！");
		}
	});//click
});
</script>